package handler

import (
	"auth-cms/model"
	"github.com/gin-gonic/gin"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	article := model.Article{
		Title:   title,
		Content: content,
	}
	err := model.DB.Create(&article).Error
	if err != nil {
		c.JSON(200, gin.H{"code": 500, "msg": "添加失败"})
		return
	}
	c.JSON(200, gin.H{"code": 200, "msg": "添加成功"})
}
func List(c *gin.Context) {
	var data []model.Article
	err := model.DB.Find(&data).Error
	if err != nil {
		c.JSON(200, gin.H{"code": 500, "msg": "查询失败"})
		return
	}
	c.JSON(200, gin.H{"code": 200, "msg": "查询成功", "data": data})
}
